import 'dart:math';

import 'package:business_getx/pages/controller/controller_test.dart';
import 'package:business_getx/pages/controller/other.dart';
import 'package:flutter/material.dart';
import 'package:lib_core/lib_core.dart';
import 'package:lib_ui/lib_ui.dart';
import 'package:lib_ui/widget/main_button.dart';

import '../../routes/get_routes.dart';

class ControllerTest2Page extends StatefulWidget {
  ControllerTest2Page({super.key});

  @override
  State<ControllerTest2Page> createState() => _ControllerTest2PageState();
}

class _ControllerTest2PageState extends State<ControllerTest2Page> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: TransparentAppBar(title: 'controller注入'),
      body: SizedBox(
        width: Get.width,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            MainButton(
              text: '通过find获取controller',
              onClick: () {
                try {
                  final controller = Get.find<ControllerTest>();
                  'controller找到了，num = ${controller.num}'.showInfo();
                } catch (e) {
                  'controller找不到'.showError();
                }
              },
            ),
            MainButton(
              text: '通过put获取controller',
              onClick: () {
                final controller = Get.put(ControllerTest());
                'controller num = ${controller.num}'.showInfo();
              },
            ),
            MainButton(
              text: '去ControllerText3页面',
              onClick: () {
                GetRoutes.controllerTest3.push();
              },
            ),
          ],
        ),
      ),
    );
  }
}
